package com.mind.customer.utils.datasource;

import com.alibaba.fastjson2.JSONObject;
import com.mind.system.domain.AjDatasource;

import java.sql.*;

public class JdbcUtils {
    private static final String URL = "jdbc:mysql://localhost:3306/your_database?serverTimezone=UTC";
    private static final String USER = "root";
    private static final String PASSWORD = "password";

    public static Connection getConnection(AjDatasource datasource) throws SQLException {
        JSONObject params = JSONObject.parseObject(datasource.getOther());
        return DriverManager.getConnection(datasource.getSourceUrl(), params.getString("username"), params.getString("password"));
    }

    public static void close(ResultSet rs, Statement stmt, Connection conn) {
        try {
            if (rs != null) rs.close();
            if (stmt != null) stmt.close();
            if (conn != null) conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
